using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using Lapointe.WebPartPageHistory.ListEventReceivers;
using Microsoft.SharePoint;

namespace Lapointe.WebPartPageHistory.ProvisioningHelpers
{
    class WebProvisioner
    {
        /// <summary>
        /// Creates the history list.
        /// </summary>
        /// <param name="web">The web.</param>
        /// <returns></returns>
        internal static SPList CreateHistoryList(SPWeb web)
        {
            Guid docLibFeatureId = new Guid("00BFEA71-E717-4E80-AA17-D0C71B360101");

            SPList list = null;
            try
            {
                bool newListCreated;
                list = ProvisioningHelper.AddList(web.Lists, HistoryHelper.LIST_WEBPARTHISTORY_URLNAME, "Web Part Page History", "", docLibFeatureId, SPListTemplateType.DocumentLibrary, out newListCreated);
                if (newListCreated)
                {
#if DEBUG
                    list.Hidden = false;
                    list.AllowDeletion = true;
#else
                    list.Hidden = true;
                    list.AllowDeletion = false;
#endif
                    list.ForceCheckout = false;
                    list.EnableVersioning = true;
                    list.EnableFolderCreation = true;
                    list.NoCrawl = true;

                    list.Update();
                }

            }
            catch (Exception ex)
            {
                Console.WriteLine("An error occured: " + ex.Message + "\r\n" + ex.StackTrace);
            }
            return list;
        }

        
    }
}